﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using TMT.Data.Common;
using System.Web.Script.Serialization;
using TMT.Data.Entities;

namespace TMT.Admin.Services
{
    /// <summary>
    /// Summary description for PageService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class PageService : System.Web.Services.WebService
    {
        [WebMethod]
        public string AddPage(string pageInfo)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            TMT.Data.Page page = serializer.Deserialize<TMT.Data.Page>(pageInfo);
            OperationResult result = TMT.Data.Base.PageService.Instance.AddPage(page);
            return result.Message;
        }

        [WebMethod]
        public string DeletePage(string pageId)
        {
            int id = int.Parse(pageId);
            OperationResult result = TMT.Data.Base.PageService.Instance.DeletePage(id);
            return result.Message;
        }

        [WebMethod]
        public string GetAllPages()
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            IList<TMTPage> pages = TMT.Data.Base.PageService.Instance.GetAllPage();
            return serializer.Serialize(pages);
        }
    }
}
